<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="后台管理系统">
    <meta name="description" content="">

    <link rel="shortcut icon" href="/static/img/favicon.ico">
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <link rel="stylesheet" type="text/css" href="http://at.alicdn.com/t/font_9h680jcse4620529.css">

<body>
<div class="larry-grid layui-anim layui-anim-upbit larryTheme-A ">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote mylog-info-tit">
                <div class="layui-inline">
                    <form class="layui-form" id="userSearchForm">
                        <div class="layui-input-inline" style="width:110px;">
                            <select name="searchTerm" >
                                <option value="code">股票代码</option>
                                <option value="name">股票姓名</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width:145px;">
                            <input type="text" name="searchContent" value="" placeholder="请输入关键字" class="layui-input search_input">
                        </div>
                        <a class="layui-btn userSearchList_btn" lay-submit lay-filter="userSearchFilter"><i class="layui-icon larry-icon larry-chaxun7"></i>查询</a>
                    </form>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal excelUserExport_btn"  style="background-color:#5FB878"> <i class="layui-icon larry-icon larry-danye"></i>导出</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-danger userBatchFail_btn"><i class="layui-icon larry-icon larry-shanchu"></i>批量失效</a>
                </div>
            </blockquote>
            <div class="larry-separate"></div>
            <!-- 用户列表 -->
            <div class="layui-tab-item layui-show " style="padding: 10px 15px;">
                <table id="stockTableList"  lay-filter="stockTableId" ></table>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var $;
    layui.config({
        base : "/static/js/"
    }).use(['form', 'table', 'layer','common'], function () {
         $ =  layui.$;
                var form = layui.form,
                table = layui.table,
                layer = layui.layer,
                common = layui.common;

        var loading = layer.load(0,{ shade: [0.3,'#000']});
        /**用户表格加载*/
        table.render({
            elem: '#stockTableList',
            url: '/stock/balanceSheet',
            id:'stockTableId',
            method: 'post',
            height:'full-140',
            skin:'row',
            even:'true',
            size: 'sm',
            limit: 16,
            page: true,
            cols: [[
                //{type:"numbers"},
                {type:"checkbox"},
                {field:'code', title: '代码',align:'center' ,width: '6%'},
                {field:'name', title: '名字',align:'center',width: '6%'},
                {field:'ann_date_str', title: '公告日期',align:'center',width: '6%'},
                {field:'end_date', title: '报告期',align:'center',width: '6%'},
                {field:'comp_type', title: '公司类型',align:'center',width: '6%'},
                {field:'total_share', title: '期末总股本',align:'center',width: '12%'},
                {field:'cap_rese', title: '资本公积金',align:'center',width: '6%'},
                {field:'undistr_porfit', title: '未分配利润',align:'center',width: '6%'},
                {field:'surplus_rese', title: '盈余公积金',align:'center',width: '6%'},
                {field:'special_rese', title: '专项储备',align:'center',width: '6%'},
                {field:'total_cur_assets', title: '流动资产合计',align:'center',width: '6%'},
                {field:'lt_rec', title: '长期应收款',align:'center',width: '6%'},
                {field:'fix_assets', title: '固定资产',align:'center',width: '7%'},
                {field:'cip', title: '在建工程',align:'center',width: '6%'},
                {field:'intan_assets', title: '无形资产',align:'center',width: '6%'},
                {field:'r_and_d', title: '研发支出',align:'center',width: '6%'},
                {field:'goodwill', title: '商誉',align:'center',width: '6%'},
                {field:'total_assets', title: '资产总计',align:'center',width: '6%'},
                {field:'lt_borr', title: '长期借款',align:'center',width: '6%'},
                {field:'st_borr', title: '短期借款',align:'center',width: '6%'},
                {field:'cb_borr', title: '向中央银行借款',align:'center',width: '6%'},
                {field:'oth_cur_liab', title: '其他流动负债',align:'center',width: '6%'},
                {field:'total_cur_liab', title: '流动负债合计',align:'center',width: '6%'},
                {field:'total_liab', title: '负债合计',align:'center',width: '6%'},
                {field:'lt_payroll_payable', title: '长期应付职工薪酬',align:'center',width: '6%'}
                //{title: '操作', align:'center', width: '10%',toolbar: '#userBar'}
            ]],
            done: function (res, curr, count) {
                common.resizeGrid();
                layer.close(loading);
            }
        });

        /**查询*/
        $(".userSearchList_btn").click(function(){
            var loading = layer.load(0,{ shade: [0.3,'#000']});
            //监听提交
            form.on('submit(userSearchFilter)', function (data) {
                table.reload('stockTableId',{
                    where: {
                            key:data.field.searchTerm,
                            value:data.field.searchContent
                    },
                    height: 'full-140',
                    page: true,
                    done: function (res, curr, count) {
                        common.resizeGrid();
                        layer.close(loading);

                    }
                });
            });
        });

        /**新增用户*/
        $(".userAdd_btn").click(function(){
            var url = "/sys/user/add";
            common.cmsLayOpen('新增用户',url,'650px','425px');
        });

        /**导出用户信息*/
        $(".excelUserExport_btn").click(function(){
            var url = '/sys/user/export';
            $("#userSearchForm").attr("action",url);
            $("#userSearchForm").submit();
        });

        /**批量失效*/
        $(".userBatchFail_btn").click(function(){
            //表格行操作
            var checkStatus = table.checkStatus('stockTableId');
            if(checkStatus.data.length == 0){
                common.cmsLayErrorMsg("请选择要失效的用户信息");
            }else{
                var currentUser = false;
                var status = false;
                var userId = '';
                var ids = [];

                for (var i=0; i< checkStatus.data.length; i++) {
                    ids.push(checkStatus.data[i].id);
                    //不能失效当前登录用户
                    if(userId == checkStatus.data[i].id){
                        currentUser = true;
                    }else{
                        currentUser = false;
                    }
                    //用户已失效
                    if(0 == checkStatus.data[i].status ){
                        status = false;
                    }else{
                        status = true;
                    }
                }

                if(currentUser == true){
                    common.cmsLayErrorMsg("当前登录用户不能被失效,请重新选择");
                    return false;
                }
                if(status == false){
                    common.cmsLayErrorMsg("当前选择的用户已失效");
                    return false;
                }
                console.log(ids);
                var url = "/sys/user/batchFail";
                var param = {userIds:ids};
                common.ajaxCmsConfirm('系统提示', '确定失效当前用户，并解除与角色绑定关系吗?',url,param);

            }

        });

        /**监听工具条*/
        table.on('tool(stockTableId)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            console.log(data);
            //修改用户
            if (layEvent === 'user_edit') {
                var id = data.id;
                var url =  "/sys/user/edit/"+id;
                common.cmsLayOpen('编辑用户',url,'550px','365px');

            //分配角色
            } else if(layEvent === 'user_grant'){
                var id = data.id;
                var status = data.status;
                if(status == 0){
                    common.cmsLayErrorMsg("当前用户已失效,不能被分配角色");
                    return false;
                }
                var url =  "/sys/user/grant/"+id;
                common.cmsLayOpen('分配角色',url,'500px','440px');

            //用户失效
            } else if(layEvent === 'user_fail') {
                var id = data.id;
                var status = data.status;
                var currentUserId = '${LOGIN_NAME.id}';/*当前登录用户的ID*/
                if(status == 0){
                    common.cmsLayErrorMsg("当前用户已失效");
                    return false;
                }
                if(id == currentUserId){
                    common.cmsLayErrorMsg("当前登陆用户不能被失效");
                    return false;
                }
                var url = "/sys/user/fail";
                var param = {userId:id};
                common.ajaxCmsConfirm('系统提示', '确定失效用户，并解除与角色绑定关系吗?',url,param);

            }
        });


    });
</script>

<!-- 用户状态tpl-->
<script type="text/html" id="statusTpl">

    {#{% if (d.status == 1) %}
    <span class="label label-success ">有效</span>
    {% elif (d.status == 0) %}
    <span class="label label-danger ">失效</span>
    {% else %}
    {{d.status}}
    {% endif  %}#}
</script>

<!--工具条 -->
<script type="text/html" id="userBar">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-xs user_edit" lay-event="user_edit"><i class="layui-icon larry-icon larry-bianji2"></i> 编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-warm  user_grant" lay-event="user_grant"><i class="layui-icon larry-icon larry-jiaoseguanli3"></i>角色</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger user_fail" lay-event="user_fail"><i class="layui-icon larry-icon larry-ttpodicon"></i>失效</a>
    </div>
</script>

</body>
</html>